package com.qinglei.recoup.test;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qinglei.recoup.system.domain.Room;
import com.qinglei.recoup.system.service.RoomService;
import com.rabbitmq.client.AMQP;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.regex.Pattern;

public class IsNumeric {
    @Autowired
    private RoomService roomService;
    @Test
    public   void isInteger() {

        List<Room> list = roomService.getRoomByBuildingId(23);
        System.out.println(list);
        list.forEach(f->{if (f.getName() != null && !"".equals(f.getName())) {
                    Pattern pattern = Pattern.compile("[0-9]*");
                    boolean matches = pattern.matcher(f.getName()).matches();
                    StringBuilder strb = new StringBuilder();
                    if (matches) {
                        int length = f.getName().length();
                        int a = 4;
                        if (length <= 4) {
                            for (int i = 0; i < a - length; i++) {
                                strb.append("0");
                            }
                        }
                    }
                    strb.append(f.getName());
                   String s = strb.toString();
            UpdateWrapper<Room> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("id",f.getId()).set("name", s);
            roomService.update(updateWrapper);
                }}

        );
    }

}
